<template>
  <a-popconfirm
    :title="title"
    @confirm="handleSubmit(shipIds)"
    okText="是"
    cancelText="否"
  >
    <a href="#">删除</a>
  </a-popconfirm>
</template>

<script>
  import { removeShip } from '@/api/ship/ship'

  export default {
    props: {
      shipIds: {
        type: String
      }
    },
    data () {
      return {
        title: '确定要删除这' + this.shipIds.split(',').length + '艘船的记录吗？'
      }
    },
    watch: {
      shipIds: function (val) {
        this.title = '确定要删除这' + val.split(',').length + '艘船的记录吗？'
      }
    },
    methods: {
      handleSubmit (shipIds) {
        removeShip({ 'shipIds': shipIds })
          .then(() => {
            this.$emit('ok')
          }).catch(err => {
          this.$message.error(err.result || '操作失败！')
        })
      }
    }
  }
</script>
